<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>拆卸设置</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/jquery-3.3.1/jquery-3.3.1.js}"></script>
</head>

<body>
<form class="layui-form"  th:action="@{/edit}" th:object="${term}" id="termFrom"  method="post">
    <input type="hidden" name="id" id="id" th:value="*{id}" />

    <div class="layui-form-item">
        <label class="layui-form-label">是否拆卸上报：</label>
        <div class="layui-input-block">
            <input type="text" name="if_chain" id="if_chain"  style="width: 400px;" placeholder="不上报输入0,上报输入其他数字"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">定位间隔：</label>
        <div class="layui-input-block">
            <input type="text" name="upload_intervel" id="upload_intervel"  style="width: 400px;" placeholder="定位间隔1-240之间的数字"  class="layui-input">
        </div>
    </div>




    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn"  th:onclick="'javascript:save()'">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>

<script>

    function save(){

        var id = $("#id").val();
        var if_chain = $("#if_chain").val();
        var upload_intervel = $("#upload_intervel").val();
        if(isNaN(if_chain)){
            parent.layer.msg("不上报输入0,上报输入其他数字");
            return;
        }
        if(isNaN(upload_intervel)){
            parent.layer.msg("定位间隔1-240之间的数字");
            return;
        }
        $.ajax({
            url: "/terminfoUpdate",
            type: "POST",
            data:{"id":id,"if_chain":if_chain,"upload_intervel":upload_intervel},
            dataType: "json",
            success: function(data){
                if(data==1){
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);  // 关闭layer
                    parent.layer.msg("修改成功", {icon: 6});
                    parent.location.reload();
                }else{
                    parent.layer.msg("修改失败", {icon: 5});
                }
            }
        });
    }

</script>
</html>